//
//  JMBCouponAddInputCell.m
//  SYPerfectDemo
//
//  Created by Lssyyy on 2019/8/8.
//  Copyright © 2019年 Lssyyy. All rights reserved.
//

#import "JMBCouponAddInputCell.h"

@interface JMBCouponAddInputCell()<UITextFieldDelegate>

@end

@implementation JMBCouponAddInputCell

- (void)addUI{
    self.topSepView.sd_layout
    .leftEqualToView(self.contentView)
    .rightEqualToView(self.contentView)
    .heightIs(10)
    .topEqualToView(self.contentView);
    
    self.titleLabel.sd_layout
    .leftSpaceToView(self.contentView, 15)
    .topSpaceToView(_topSepView, 0)
    .heightIs(50);
    [self.titleLabel setSingleLineAutoResizeWithMaxWidth:0.4 *UI_SCREEN_WIDTH];
    
    self.unitLabel.sd_layout
    .leftSpaceToView(self.titleLabel,5)
    .centerYEqualToView(self.titleLabel)
    .heightIs(50);
    [self.unitLabel setSingleLineAutoResizeWithMaxWidth:0.2 *UI_SCREEN_WIDTH];
    
    self.contentTextField.sd_layout
    .leftSpaceToView(self.unitLabel, 5)
    .rightSpaceToView(self.contentView, 15)
    .heightIs(50)
    .centerYEqualToView(self.titleLabel);
}

- (void)setItem:(CouponFormItem *)item{
    _item = item;
    self.titleLabel.attributedText = item.attributedTitle;
    self.unitLabel.text = item.unit;
    self.contentTextField.placeholder = item.placeholder;
    self.contentTextField.text = item.info;
}

- (void)textFieldDidEndEditing:(UITextField *)textField{
    if (self.inputEndCompletion) {
        self.inputEndCompletion(self.contentTextField.text);
    }
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.font = [UIFont systemFontOfSize:14];
        _titleLabel.textColor = UIColorHex(333333);
        [self.contentView addSubview:_titleLabel];
    }
    return _titleLabel;
}

- (UILabel *)unitLabel{
    if (!_unitLabel) {
        _unitLabel = [[UILabel alloc]init];
        _unitLabel.font = [UIFont systemFontOfSize:14];
        _unitLabel.textColor = UIColorHex(B2B2B2);
        _unitLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:_unitLabel];
    }
    return _unitLabel;
}

- (UITextField *)contentTextField{
    if (!_contentTextField) {
        _contentTextField = [[UITextField alloc]init];
        _contentTextField.font = [UIFont systemFontOfSize:14];
        _contentTextField.textColor = UIColorHex(333333);
        _contentTextField.delegate = self;
        _contentTextField.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:_contentTextField];
    }
    return _contentTextField;
}

- (UIView *)topSepView{
    if (!_topSepView) {
        _topSepView = [UIView new];
        _topSepView.backgroundColor = UIColorHex(F3F3F3);
        [self.contentView addSubview:_topSepView];
    }
    return _topSepView;
}
@end
